﻿using System;
using System.Collections.Generic;
using System.Data;
using nkstdgia.common.ThamDinhGia.BusinessObjects;

namespace nkstdgia.common.ThamDinhGia.DataAccess
{
    public class VAT_LIEU_XAY_DUNGDA
    {
        #region ***** Init Methods *****

        public VAT_LIEU_XAY_DUNGDA()
        {
        }

        #endregion ***** Init Methods *****

        #region ***** Get Methods *****

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public VAT_LIEU_XAY_DUNG Populate(IDataReader myReader)
        {
            VAT_LIEU_XAY_DUNG obj = new VAT_LIEU_XAY_DUNG();
            obj.MA_HO_SO = (Int64)myReader["MA_HO_SO"];
            obj.LOAI_KET_CAU_KHUNG = (Int64)myReader["LOAI_KET_CAU_KHUNG"];
            obj.NOI_DUNG_KET_CAU_KHUNG = myReader["NOI_DUNG_KET_CAU_KHUNG"] != DBNull.Value ? (string)myReader["NOI_DUNG_KET_CAU_KHUNG"] : "";
            obj.LOAI_KET_CAU_MONG = (Int64)myReader["LOAI_KET_CAU_MONG"];
            obj.NOI_DUNG_KET_CAU_MONG = myReader["NOI_DUNG_KET_CAU_MONG"] != DBNull.Value ? (string)myReader["NOI_DUNG_KET_CAU_MONG"] : "";
            obj.LOAI_KET_CAU_TUONG_NHA = (Int64)myReader["LOAI_KET_CAU_TUONG_NHA"];
            obj.NOI_DUNG_KET_CAU_TUONG_NHA = myReader["NOI_DUNG_KET_CAU_TUONG_NHA"] != DBNull.Value ? (string)myReader["NOI_DUNG_KET_CAU_TUONG_NHA"] : "";
            obj.LOAI_KET_CAU_NEN = (Int64)myReader["LOAI_KET_CAU_NEN"];
            obj.NOI_DUNG_KET_CAU_NEN = myReader["NOI_DUNG_KET_CAU_NEN"] != DBNull.Value ? (string)myReader["NOI_DUNG_KET_CAU_NEN"] : "";
            obj.LOAI_KET_CAU_MAI = (Int64)myReader["LOAI_KET_CAU_MAI"];
            obj.NOI_DUNG_KET_CAU_MAI = myReader["NOI_DUNG_KET_CAU_MAI"] != DBNull.Value ? (string)myReader["NOI_DUNG_KET_CAU_MAI"] : "";
            obj.CHAT_LUONG_MONG = myReader["CHAT_LUONG_MONG"] != DBNull.Value ? (double)myReader["CHAT_LUONG_MONG"] : 0.0;
            obj.CHAT_LUONG_SAN = myReader["CHAT_LUONG_SAN"] != DBNull.Value ? (double)myReader["CHAT_LUONG_SAN"] : 0.0;
            obj.CHAT_LUONG_TUONG = myReader["CHAT_LUONG_TUONG"] != DBNull.Value ? (double)myReader["CHAT_LUONG_TUONG"] : 0.0;
            obj.CHAT_LUONG_TRAN = myReader["CHAT_LUONG_TRAN"] != DBNull.Value ? (double)myReader["CHAT_LUONG_TRAN"] : 0.0;
            obj.CHAT_LUONG_MAI = myReader["CHAT_LUONG_MAI"] != DBNull.Value ? (double)myReader["CHAT_LUONG_MAI"] : 0.0;
            obj.TI_LE_KET_CAU_MONG = myReader["TI_LE_KET_CAU_MONG"] != DBNull.Value ? (double)myReader["TI_LE_KET_CAU_MONG"] : 0.0;
            obj.TI_LE_KET_CAU_SAN = myReader["TI_LE_KET_CAU_SAN"] != DBNull.Value ? (double)myReader["TI_LE_KET_CAU_SAN"] : 0.0;
            obj.TI_LE_KET_CAU_TUONG = myReader["TI_LE_KET_CAU_TUONG"] != DBNull.Value ? (double)myReader["TI_LE_KET_CAU_TUONG"] : 0.0;
            obj.TI_LE_KET_CAU_TRAN = myReader["TI_LE_KET_CAU_TRAN"] != DBNull.Value ? (double)myReader["TI_LE_KET_CAU_TRAN"] : 0.0;
            obj.TI_LE_KET_CAU_MAI = myReader["TI_LE_KET_CAU_MAI"] != DBNull.Value ? (double)myReader["TI_LE_KET_CAU_MAI"] : 0.0;
            obj.SO_PHONG_NGU = (int)myReader["SO_PHONG_NGU"];
            obj.SO_NHA_VE_SINH = (int)myReader["SO_NHA_VE_SINH"];
            obj.LOAI_TRANG_TRI_NOI_THAT = (Int64)myReader["LOAI_TRANG_TRI_NOI_THAT"];
            obj.NOI_DUNG_TRANG_TRI_NOI_THAT = myReader["NOI_DUNG_TRANG_TRI_NOI_THAT"] != DBNull.Value ? (string)myReader["NOI_DUNG_TRANG_TRI_NOI_THAT"] : "";
            obj.LOAI_CONG_TRINH_XAY_DUNG = (Int64)myReader["LOAI_CONG_TRINH_XAY_DUNG"];
            obj.NOI_DUNG_CONG_TRINH_XAY_DUNG = myReader["NOI_DUNG_CONG_TRINH_XAY_DUNG"] != DBNull.Value ? (string)myReader["NOI_DUNG_CONG_TRINH_XAY_DUNG"] : "";
            return obj;
        }

        /// <summary>
        /// Get VAT_LIEU_XAY_DUNG by ma_ho_so
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns>VAT_LIEU_XAY_DUNG</returns>
        public VAT_LIEU_XAY_DUNG GetByMA_HO_SO(Int64 ma_ho_so)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_GetByMA_HO_SO", Data.CreateParameter("MA_HO_SO", ma_ho_so)))
            {
                if (reader.Read())
                {
                    return Populate(reader);
                }
                return null;
            }
        }

        /// <summary>
        /// Get all of VAT_LIEU_XAY_DUNG
        /// </summary>
        /// <returns>List<<VAT_LIEU_XAY_DUNG>></returns>
        public List<VAT_LIEU_XAY_DUNG> GetList()
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_Get"))
            {
                List<VAT_LIEU_XAY_DUNG> list = new List<VAT_LIEU_XAY_DUNG>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of VAT_LIEU_XAY_DUNG
        /// </summary>
        /// <returns>DataSet</returns>
        public DataSet GetDataSet()
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_Get");
        }

        /// <summary>
        /// Get all of VAT_LIEU_XAY_DUNG paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>List<<VAT_LIEU_XAY_DUNG>></returns>
        public List<VAT_LIEU_XAY_DUNG> GetListPaged(int recperpage, int pageindex)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex)))
            {
                List<VAT_LIEU_XAY_DUNG> list = new List<VAT_LIEU_XAY_DUNG>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of VAT_LIEU_XAY_DUNG paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>DataSet</returns>
        public DataSet GetDataSetPaged(int recperpage, int pageindex)
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex));
        }

        #endregion ***** Get Methods *****

        #region ***** Add Update Delete Methods *****

        /// <summary>
        /// Add a new VAT_LIEU_XAY_DUNG within VAT_LIEU_XAY_DUNG database table
        /// </summary>
        /// <param name="obj">VAT_LIEU_XAY_DUNG</param>
        /// <returns>key of table</returns>
        public long Add(VAT_LIEU_XAY_DUNG obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_Add"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("LOAI_KET_CAU_KHUNG", obj.LOAI_KET_CAU_KHUNG)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_KHUNG", obj.NOI_DUNG_KET_CAU_KHUNG)
                            , Data.CreateParameter("LOAI_KET_CAU_MONG", obj.LOAI_KET_CAU_MONG)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_MONG", obj.NOI_DUNG_KET_CAU_MONG)
                            , Data.CreateParameter("LOAI_KET_CAU_TUONG_NHA", obj.LOAI_KET_CAU_TUONG_NHA)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_TUONG_NHA", obj.NOI_DUNG_KET_CAU_TUONG_NHA)
                            , Data.CreateParameter("LOAI_KET_CAU_NEN", obj.LOAI_KET_CAU_NEN)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_NEN", obj.NOI_DUNG_KET_CAU_NEN)
                            , Data.CreateParameter("LOAI_KET_CAU_MAI", obj.LOAI_KET_CAU_MAI)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_MAI", obj.NOI_DUNG_KET_CAU_MAI)
                            , Data.CreateParameter("CHAT_LUONG_MONG", obj.CHAT_LUONG_MONG)
                            , Data.CreateParameter("CHAT_LUONG_SAN", obj.CHAT_LUONG_SAN)
                            , Data.CreateParameter("CHAT_LUONG_TUONG", obj.CHAT_LUONG_TUONG)
                            , Data.CreateParameter("CHAT_LUONG_TRAN", obj.CHAT_LUONG_TRAN)
                            , Data.CreateParameter("CHAT_LUONG_MAI", obj.CHAT_LUONG_MAI)
                            , Data.CreateParameter("TI_LE_KET_CAU_MONG", obj.TI_LE_KET_CAU_MONG)
                            , Data.CreateParameter("TI_LE_KET_CAU_SAN", obj.TI_LE_KET_CAU_SAN)
                            , Data.CreateParameter("TI_LE_KET_CAU_TUONG", obj.TI_LE_KET_CAU_TUONG)
                            , Data.CreateParameter("TI_LE_KET_CAU_TRAN", obj.TI_LE_KET_CAU_TRAN)
                            , Data.CreateParameter("TI_LE_KET_CAU_MAI", obj.TI_LE_KET_CAU_MAI)
                            , Data.CreateParameter("SO_PHONG_NGU", obj.SO_PHONG_NGU)
                            , Data.CreateParameter("SO_NHA_VE_SINH", obj.SO_NHA_VE_SINH)
                            , Data.CreateParameter("LOAI_TRANG_TRI_NOI_THAT", obj.LOAI_TRANG_TRI_NOI_THAT)
                            , Data.CreateParameter("NOI_DUNG_TRANG_TRI_NOI_THAT", obj.NOI_DUNG_TRANG_TRI_NOI_THAT)
                            , Data.CreateParameter("LOAI_CONG_TRINH_XAY_DUNG", obj.LOAI_CONG_TRINH_XAY_DUNG)
                            , Data.CreateParameter("NOI_DUNG_CONG_TRINH_XAY_DUNG", obj.NOI_DUNG_CONG_TRINH_XAY_DUNG)
            );
            return obj.MA_HO_SO;
        }

        /// <summary>
        /// updates the specified VAT_LIEU_XAY_DUNG
        /// </summary>
        /// <param name="obj">VAT_LIEU_XAY_DUNG</param>
        /// <returns></returns>
        public void Update(VAT_LIEU_XAY_DUNG obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_Update"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("LOAI_KET_CAU_KHUNG", obj.LOAI_KET_CAU_KHUNG)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_KHUNG", obj.NOI_DUNG_KET_CAU_KHUNG)
                            , Data.CreateParameter("LOAI_KET_CAU_MONG", obj.LOAI_KET_CAU_MONG)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_MONG", obj.NOI_DUNG_KET_CAU_MONG)
                            , Data.CreateParameter("LOAI_KET_CAU_TUONG_NHA", obj.LOAI_KET_CAU_TUONG_NHA)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_TUONG_NHA", obj.NOI_DUNG_KET_CAU_TUONG_NHA)
                            , Data.CreateParameter("LOAI_KET_CAU_NEN", obj.LOAI_KET_CAU_NEN)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_NEN", obj.NOI_DUNG_KET_CAU_NEN)
                            , Data.CreateParameter("LOAI_KET_CAU_MAI", obj.LOAI_KET_CAU_MAI)
                            , Data.CreateParameter("NOI_DUNG_KET_CAU_MAI", obj.NOI_DUNG_KET_CAU_MAI)
                            , Data.CreateParameter("CHAT_LUONG_MONG", obj.CHAT_LUONG_MONG)
                            , Data.CreateParameter("CHAT_LUONG_SAN", obj.CHAT_LUONG_SAN)
                            , Data.CreateParameter("CHAT_LUONG_TUONG", obj.CHAT_LUONG_TUONG)
                            , Data.CreateParameter("CHAT_LUONG_TRAN", obj.CHAT_LUONG_TRAN)
                            , Data.CreateParameter("CHAT_LUONG_MAI", obj.CHAT_LUONG_MAI)
                            , Data.CreateParameter("TI_LE_KET_CAU_MONG", obj.TI_LE_KET_CAU_MONG)
                            , Data.CreateParameter("TI_LE_KET_CAU_SAN", obj.TI_LE_KET_CAU_SAN)
                            , Data.CreateParameter("TI_LE_KET_CAU_TUONG", obj.TI_LE_KET_CAU_TUONG)
                            , Data.CreateParameter("TI_LE_KET_CAU_TRAN", obj.TI_LE_KET_CAU_TRAN)
                            , Data.CreateParameter("TI_LE_KET_CAU_MAI", obj.TI_LE_KET_CAU_MAI)
                            , Data.CreateParameter("SO_PHONG_NGU", obj.SO_PHONG_NGU)
                            , Data.CreateParameter("SO_NHA_VE_SINH", obj.SO_NHA_VE_SINH)
                            , Data.CreateParameter("LOAI_TRANG_TRI_NOI_THAT", obj.LOAI_TRANG_TRI_NOI_THAT)
                            , Data.CreateParameter("NOI_DUNG_TRANG_TRI_NOI_THAT", obj.NOI_DUNG_TRANG_TRI_NOI_THAT)
                            , Data.CreateParameter("LOAI_CONG_TRINH_XAY_DUNG", obj.LOAI_CONG_TRINH_XAY_DUNG)
                            , Data.CreateParameter("NOI_DUNG_CONG_TRINH_XAY_DUNG", obj.NOI_DUNG_CONG_TRINH_XAY_DUNG)
            );
        }

        /// <summary>
        /// Delete the specified VAT_LIEU_XAY_DUNG
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns></returns>
        public void Delete(Int64 ma_ho_so)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_VAT_LIEU_XAY_DUNG_Delete", Data.CreateParameter("MA_HO_SO", ma_ho_so));
        }

        #endregion ***** Add Update Delete Methods *****
    }
}